package io.renren.handler;

import io.renren.builder.TextBuilder;
import io.renren.core.config.ProjectConStant;
import io.renren.entity.Book;
import io.renren.entity.BookVideo;
import io.renren.entity.UserDefaultInfo;
import io.renren.entity.WxUser;
import io.renren.service.BookVideoService;
import io.renren.service.UserDefaultInfoService;
import io.renren.service.WxUserService;
import io.renren.utils.ConfigConstant;
import io.renren.utils.QrLogicUtil;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutNewsMessage;
import me.chanjar.weixin.mp.bean.result.WxMpUser;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author Binary Wang(https://github.com/binarywang)
 */
@Component
@Slf4j
public class ScanHandler extends AbstractHandler {

    @Autowired
    private VideoHandleUtils videoHandleUtils;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context,
                                    WxMpService wxMpService,
                                    WxSessionManager sessionManager) {
        String eventKey = wxMessage.getEventKey();
        if (eventKey.startsWith(ProjectConStant.EXAM_PAPER_QR_CODE_PREFIX)) {
            return null;
        }

        //===================================
        return videoHandleUtils.getVideoListWxMpXmlOutMessage(wxMessage, wxMpService, eventKey);
    }

}
